<% 

Sub userMenuAddScripts
 	Response.Write("<link rel=""stylesheet"" type=""text/css"" href=""includes/dhtmlxSuite/dhtmlxMenu/codebase/skins/dhtmlxmenu_dhx_web_gwm.css"">")
	Response.Write("<script src=""includes/dhtmlxSuite/dhtmlxMenu/codebase/dhtmlxcommon.js""></script>")
	Response.Write("<script src=""includes/dhtmlxSuite/dhtmlxMenu/codebase/dhtmlxmenu.js""></script>")
	Response.Write("<script src=""includes/dhtmlxSuite/dhtmlxMenu/codebase/ext/dhtmlxmenu_ext.js"" type=""text/javascript""></script>")
End Sub
 
Sub userMenuWriteMenuObj(menuObjId)
	Response.Write("<div style=""height: 21px; padding-top: 1px; ""><div id=""" & menuObjId & """></div></div>")
End Sub

Sub userMenuWriteSubItems(objConn, menuId, parentItemId, lng_id)
	On Error Resume Next
	
	dim queryStr, rst, strFieldName, strText, strLink, prevSibling
	
	Set rst = Server.CreateObject("ADODB.Recordset")
	
	If Err.Number Then
		Response.Write("//Errors(1.1): " & Err.Description)
		Err.Clear
	End If
	If ( Cint(lng_id) = 1 ) Then
		strFieldName = "german"
	else
		strFieldName = "english"
	End If
	
	queryStr = "SELECT mi_id, level_order_index, IFNULL(str_" & strFieldName & ", '') AS TEXT, IFNULL(str_link_" & strFieldName & ", '') AS LINK " &_
				 "FROM tbl_0959_menu_items "&_
				"WHERE parent_mi_id = '" & parentItemId & "' "&_
				 "AND um_id = '" & menuId & "' "&_
				"ORDER BY level_order_index"
	rst.Open queryStr, objConn
	
	If Err.Number Then
		Response.Write("//Errors(1.2): " & Err.Description)
		Err.Clear
	End If
	
	prevSibling = "null"
	Do While ( Not rst.EOF ) 
		strText = rst.Fields("TEXT")
		strLink = escape(rst.Fields("LINK"))
		If Err.Number Then
			Response.Write("//Errors(1.3): " & Err.Description)
			Err.Clear
			Exit Do
		End If
		If ( strText = "-" ) And ( prevSibling <> "null" ) then
			Response.Write("menu.addNewSeparator(" & prevSibling & ", ""mi_" & rst.Fields("mi_id") & """);")
		Else
			If ( parentItemId = -1 ) Then
				Response.Write("menu.addNewSibling(" & prevSibling & ", ""mi_" & rst.Fields("mi_id") & """, """ & strText & """, false);")
			Else
				Response.Write("menu.addNewChild(""mi_" & parentItemId & """, " & rst.Fields("level_order_index") & ", ""mi_" & rst.Fields("mi_id") & """, """ & strText & """, false);")
			End If
		End If
		Response.Write(Chr(13) & Chr(10))
		prevSibling = """mi_" & rst.Fields("mi_id") & """"
		Response.Write("menu.setUserData(""mi_" & rst.Fields("mi_id") & """, ""link"", """ & strLink & """);" & Chr(13) & Chr(10))
		If Err.Number Then
			Response.Write("//Errors(1.4): " & Err.Description)
			Err.Clear
			Exit Do
		End If
		CALL userMenuWriteSubItems(objConn, menuId, Cint(rst.Fields("mi_id")), lng_id)
		rst.MoveNext		 
	Loop
	
	If Err.Number Then
		Response.Write("//Errors(1.5): " & Err.Description)
		Err.Clear
	End If
	
	rst.Close
	Set rst = Nothing
	If Err.Number Then
		Response.Write("//Errors(1.6): " & Err.Description)
		Err.Clear
	End If
End Sub
	
Sub userMenuWriteInitScript(menuObjId, objConn, userGroupId, lng_id)
	On Error Resume Next
		
	dim queryStr, rst, menuId
	
	Set rst = Server.CreateObject("ADODB.Recordset")
	
	queryStr = "SELECT um_id FROM tbl_0958_user_menu WHERE lng_fk_user_group = '" & userGroupId & "'"
	rst.Open queryStr, objConn

	If ( not rst.Eof ) Then 
		Response.Write("<script>")
		Response.Write("var menu = new dhtmlXMenuObject(""" & menuObjId & """, ""dhx_web_gwm"");")
	
		menuId = rst.Fields("um_id")
		rst.Close
		Set rst = Nothing
		
		CALL userMenuWriteSubItems(objConn, menuId, -1, lng_id)
	
		Response.Write("menu.attachEvent(""onClick"", function(id, zoneId, casState){")
			Response.Write("var link = menu.getUserData(id, ""link"");")
			Response.Write("if ( link ) {")
				Response.Write("window.location.href = unescape(link);")
			Response.Write("}")
		Response.Write("})")
	
		If Err.Number Then
			Response.Write("//Errors: " & Err.Description)
			Err.Clear
		End If
	
		Response.Write("</script>")
	End If
End Sub

Function getGroupByUser(objConn, userId)
	dim queryStr, rst
	Set rst = Server.CreateObject("ADODB.Recordset")
	
	queryStr = "SELECT lng_fk_user_group FROM tbl_0501_user WHERE lng_k_User_ID = '" & userId & "'"
	rst.Open queryStr, objConn

	If ( not rst.Eof ) Then
		getGroupByUser = CInt(rst.Fields("lng_fk_user_group"))
	Else
		getGroupByUser = -1
	End If
End Function

Sub userMenuInsertPagePath(objConn, userGroupId, lng_id, pageName)
	CALL userMenuInsertPagePath2(objConn, userGroupId, lng_id, pageName, "", "")
End Sub

Sub userMenuInsertPagePath2(objConn, userGroupId, lng_id, pageName, additionalPartLeft, additionalPartRight)
	dim queryStr, rst, menuId, strFieldName, strText, sPath, parentMiId
	On Error Resume Next
	
	Set rst = Server.CreateObject("ADODB.Recordset")
	
	queryStr = "SELECT um_id FROM tbl_0958_user_menu WHERE lng_fk_user_group = '" & userGroupId & "'"
	rst.Open queryStr, objConn

	If ( not rst.Eof ) Then 

		menuId = rst.Fields("um_id")
		rst.Close
	
		If Err.Number Then
			Response.Write("//Errors(2.1): " & Err.Description)
			Err.Clear
		End If
		If ( Cint(lng_id) = 1 ) Then
			strFieldName = "german"
		else
			strFieldName = "english"
		End If

		queryStr = "SELECT parent_mi_id, IFNULL(str_" & strFieldName & ", '') AS TEXT "&_
					"FROM tbl_0959_menu_items " &_
					"WHERE um_id = '" & menuId & "' "&_
					"AND str_link_" & strFieldName & " = """ & pageName & """"
		rst.Open queryStr, objConn
	
		If ( not rst.Eof ) Then 
			parentMiId = CInt(rst.Fields("parent_mi_id"))
			sPath = rst.Fields("TEXT")			
			rst.Close
			
			Do While ( parentMiId <> -1 ) 
				queryStr = "SELECT parent_mi_id, IFNULL(str_" & strFieldName & ", '') AS TEXT " &_
							"FROM tbl_0959_menu_items " &_
							"WHERE um_id = '" & menuId & "' " &_
							"AND mi_id = '" & parentMiId & "'"
				rst.Open queryStr, objConn

				If Err.Number Then
					Response.Write("//Errors(2.2): " & Err.Description)
					Err.Clear
					Exit Do
				End If
				if ( not rst.Eof ) Then				
					parentMiId = CInt(rst.Fields("parent_mi_id"))
					sPath = rst.Fields("TEXT") & " | " & sPath
					rst.Close
				Else
					parentMiId = -1
				End If
				If Err.Number Then
					Response.Write("//Errors(2.3): " & Err.Description)
					Err.Clear
					Exit Do
				End If
			Loop
			
			If Err.Number Then
				Response.Write("//Errors(2.4): " & Err.Description)
				Err.Clear
			End If

			Response.Write("<div style=""white-space:nowrap; font-size: 11px; font-family: Tahoma; "">")
			If ( additionalPartLeft <> "" ) Then
				Response.Write(additionalPartLeft)
			End If
			Response.Write(fc_value_string(lng_id, "var_glob_txt_05") & " " & sPath)
			If ( additionalPartRight <> "" ) Then
				Response.Write(additionalPartRight)
			End If
			Response.Write("</div>")
			
			If Err.Number Then
				Response.Write("//Errors(2.5): " & Err.Description)
				Err.Clear
			End If
			
		End If
		Set rst = Nothing
	End If
	If Err.Number Then
		Response.Write("//Errors(2.5): " & Err.Description)
		Err.Clear
	End If
End Sub

Sub writeGwmCustomHeaders
	Response.Write("<meta http-equiv=""X-UA-Compatible"" content=""IE=EmulateIE7,IE=edge"">")
End Sub

Function userMenuWriteSubItems2(objConn, menuId, parentItemId, lng_id)
	On Error Resume Next
	
	dim queryStr, rst, strFieldName, strText, strLink, prevSibling, json
	
	Set rst = Server.CreateObject("ADODB.Recordset")
	
	If Err.Number Then
		Response.Write("//Errors(1.1): " & Err.Description)
		Err.Clear
	End If
	If ( Cint(lng_id) = 1 ) Then
		strFieldName = "german"
	else
		strFieldName = "english"
	End If
	
	queryStr = "SELECT a.mi_id, a.level_order_index, a.parent_mi_id," &_ 
				"IFNULL(a.str_" & strFieldName & ", '') AS TEXT, IFNULL(a.str_link_" & strFieldName & ", '') AS LINK, " &_
				"(SELECT count(1) FROM tbl_0959_menu_items WHERE um_id = '" & menuId & "' AND parent_mi_id = a.mi_id) HAS_CHILD " &_
				"FROM tbl_0959_menu_items a "&_
				"WHERE a.um_id = '" & menuId & "' "&_
				"AND IFNULL(a.str_" & strFieldName & ", '') <> '-' " &_
				"ORDER BY a.level_order_index"
	rst.Open queryStr, objConn
	
	If Err.Number Then
		Response.Write("//Errors(1.2): " & Err.Description)
		Err.Clear
	End If
	json = ""
	Do While ( Not rst.EOF ) 
		strText = rst.Fields("TEXT")
		strLink = escape(rst.Fields("LINK"))
		If Err.Number Then
			Response.Write("//Errors(1.3): " & Err.Description)
			Err.Clear
			Exit Do
		End If
		json = json & vbNewLine & "{parent_mi_id: '"&rst.Fields("parent_mi_id")&"', mi_id: '"&rst.Fields("mi_id")&_
									"', level_order_index: '"&rst.Fields("level_order_index")&"', TEXT: '"&rst.Fields("TEXT")&_
									"', LINK: '"&escape(rst.Fields("LINK"))&"', has_child: '"&rst.Fields("HAS_CHILD")&"'}, "
		rst.MoveNext		 
	Loop
	userMenuWriteSubItems2 = json
	If Err.Number Then
		Response.Write("//Errors(1.5): " & Err.Description)
		Err.Clear
	End If
	
	rst.Close
	Set rst = Nothing
	If Err.Number Then
		Response.Write("//Errors(1.6): " & Err.Description)
		Err.Clear
	End If
End Function

%>